package com.yzl.springboot.springboot.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yzl.springboot.springboot.domain.Video;
import com.yzl.springboot.springboot.service.VideoService;
import com.yzl.springboot.springboot.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: VideoController
 * @Author: 姚志立
 * @Description:视频控制器
 * @Date: 2020/5/23 23:43
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api/v1/pub/video")
public class VideoController {
    @Autowired
    private VideoService videoService;

    //    @RequestMapping(value = "list",method = RequestMethod.GET)
    @GetMapping("list")
    public Object list() throws JsonProcessingException {
        List<Video> list = videoService.listVideo();
//        序列化
//        ObjectMapper objectMapper = new ObjectMapper();
//        String jsonStr = objectMapper.writeValueAsString(list);
//        System.out.println(jsonStr);
//        反序列化
//        List<Video> temp = objectMapper.readValue(jsonStr, List.class);

        return JsonData.buildSuccess(list);
    }

    @PostMapping("save_video_chapter")
    public JsonData saveVideo(@RequestBody Video video) {
        System.out.println(video.toString());
        return JsonData.buildSuccess(video);
    }
}
